package dal.daoimpl;

import dal.dao.UserDao;
import dal.entity.User;
import dal.util.DBUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {

    @Override
    public boolean addUser(User user) {
        String insert = "insert user00(uname,upassword) values('"+user.getUname()+"','"+user.getUpassword()+"')";
        System.out.println(insert);
        try {
            DBUtil.runUpdate(insert);
            return true;
        } catch (SQLException e) {
            return false;
        }
    }

    @Override
    public boolean delUserbyID(int id) {
        return false;
    }

    @Override
    public boolean updateUser(User user) {
        return false;
    }

    @Override
    public User getUserbyID(int id) {
        return null;
    }

    @Override
    public boolean exists(User user) {
        String select = "select * from user00 where uname = '"+user.getUname()+"'and upassword='"+user.getUpassword()+"'";
        System.out.println(select);
        try {
            ResultSet rs = DBUtil.runQuery(select);
            if(rs.next()) {
                DBUtil.realeaseAll();
                return true;
            }else {
                DBUtil.realeaseAll();
                return false;
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }



}
